package com.pucong.gitee.database.backup.business.database.util;

import com.pucong.gitee.database.backup.common.entity.database.DatabaseTable;
import com.pucong.gitee.database.backup.common.entity.database.DatabaseTableFiled;
import com.pucong.gitee.database.backup.business.database.vo.ExeSqlResult;

import java.math.BigDecimal;
import java.util.List;

public interface OperationService {

    /**
     * 获取数据库list
     * @return
     */
    ExeSqlResult getDataBaseList();

    /**
     * 获取模式list
     * @return
     */
    List<String> getSchemaList(String databaseName);

    /**
     * 根据数据源获取所有表名
     * @return
     * @param schemaname
     */
    List<DatabaseTable> getTableListByDBInfo(String schemaname);

    /**
     * 根据数据源和表名获取字段信息
     *
     * @param schemaName
     * @param tableName
     * @return
     */
    List<DatabaseTableFiled> getTableFileListByDBInfo(String schemaName,String tableName);

    /**
     * 根据数据源和表名获取数据
     * @param tableName
     * @param pageSize
     * @param pageNo
     * @return
     */
    ExeSqlResult getTableDataListByDBInfo(String tableName, int pageSize,int pageNo);

    /**
     * 执行sql文件
     */
    Boolean runSqlByScriptRunner(String sqlPath);

    /**
     * 创建连接
     */
    Boolean getConnection();

    /**
     * 关闭连接
     */
    void closeAll();

    /**
     * 生成分页sql
     * @param sql
     * @param pageNo
     * @param pageSize
     * @return
     * @throws Exception
     */
    String generatePageSql(String sql, Integer pageNo, Integer pageSize);

    /**
     * 得到查询总数
     * @param sql
     * @return
     */
    BigDecimal getCountByQuerySql(String sql);

    /**
     * 执行更新语句
     * @param sql
     * @param params
     * @return
     */
    public int executeUpdate(String sql, Object[] params);

    /**
     * 执行查询语句
     * @param sql
     * @param params
     * @return
     */
    public ExeSqlResult executeQuery(String sql, Object[] params);

    void initUrl();

    void setDataBase(String databaseName);

    void setSchema(String schema);

    void trueAutoCommit();

    void falseAutoCommit();

    void commitTransactional();

    void setSessionId(String sessionId);

    String getSessionId();

    Boolean dropDatabase(String name);

    Boolean renameDatabase(String name,String toName);

    Boolean dropDataSchema(String name);

    Boolean renameDataSchema(String name,String toName);

    Boolean dropDataTable(String name);

    Boolean renameDataTable(String name,String toName);

    Boolean addDataTableFiled(String tableName,DatabaseTableFiled addDatabaseTableFiled);

    Boolean deleteDataTableFiled(String tableName,String tableFiled);

    Boolean alertDataTableFiled(String tableName,String tableFiled,DatabaseTableFiled toDatabaseTableFiled);

    Boolean addFiledPk(String tableName,String tableFiled);

    Boolean deleteFiledPk(String tableName,String tableFiled);
}